﻿@model JiesuanMasterModel
@{
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    var viewModel = Model ?? new JiesuanMasterModel();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
}

<form id="S_Form" action="@Url.Action("jiesuanauding", "jiesuan")" method="post" class="definewidth m20" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="2" width="50%">
                <h5>
                    @ViewBag.Title，标<em>*</em>号是必填或必选项。
                </h5>
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">结算单类型</td>
            <td>
                货款（向供应商付款）
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">收款方信息</td>
            <td>
                <table>
                    <tr>
                        <td>
                            @{
                                var suinfo = dbcontext.ADZ_SupplierMaster.FirstOrDefault(t => t.supplier_id == viewModel.aDZ_JiesuanMaster.supplier_id);
                                if (suinfo != null)
                                {
                                    <info>
                                        名称：@suinfo.supplier_name
                                        <br />联系人：@suinfo.contact_name
                                        <br />联系电话：@suinfo.telephone
                                        <br />联系地址：@suinfo.city_name @suinfo.supplier_address
                                    </info>
                                }
                            }
                        </td>
                        <td>
                            <info id="tdPayInfo">
                                付款货币：<br />
                                是否开票：           <br />
                                付款渠道：           <br />
                                收款方开户行：           <br />
                                收款方银行账号：           <br />
                                收款方银行开户名：           <br />
                                公司账户：           <br />
                            </info>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">订单金额</td>
            <td>
                @viewModel.aDZ_JiesuanMaster.order_money
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">供货金额</td>
            <td>
                @viewModel.aDZ_JiesuanMaster.supply_money
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">申请结算金额</td>
            <td>
                @viewModel.aDZ_JiesuanMaster.jiesuan_money（@(MyEnumHelper.GetEnumItemDescription<CurrencyType>(viewModel.aDZ_JiesuanMaster.currency_type))）
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">实际结算金额<em>*</em></td>
            <td>
                <input type="text" name="aDZ_JiesuanMaster.jiesuan_money_real" id="jiesuan_money_real" style="width:300px;" value="@viewModel.aDZ_JiesuanMaster.jiesuan_money_real" />（@(MyEnumHelper.GetEnumItemDescription<CurrencyType>(viewModel.aDZ_JiesuanMaster.currency_type))）
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">备注</td>
            <td>
                <textarea name="aDZ_JiesuanMaster.remark" id="remark" style="width:80%;" maxlength="2500" placeholder="" cols="4">@viewModel.aDZ_JiesuanMaster.remark</textarea>
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">驳回原因</td>
            <td>
                <textarea name="aDZ_JiesuanMaster.reject_reson" id="reject_reson" style="width:80%;" maxlength="2500" placeholder="" cols="4">@viewModel.aDZ_JiesuanMaster.reject_reson</textarea>
            </td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td colspan="3">
                <p>
                    <span id="spMsg"></span>
                </p>
                <button type="button" id="caiwupass" class="btn btn-primary">提交总经理审核</button> &nbsp;&nbsp;
                <button type="button" id="caiwurefuse" class="btn btn-primary">驳回结算单</button> &nbsp;&nbsp;

                <button type="button" class="btn btn-success" name="backid" id="backid">返回</button>
            </td>
        </tr>
    </table>

    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="2" width="50%">
                <h5>
                    结算订单明细
                </h5>
            </td>
        </tr>
    </table>
    <table class="table table-bordered table-hover definewidth m10">
        <thead>
            <tr>
                <th>序号</th>
                <th>发起时间</th>
                <th>发起人</th>
                <th>订单号</th>
                <th>付款类型</th>
                <th>付款渠道</th>
                <th>是否含税</th>
                <th>付款货币</th>
                <th>订单金额</th>
                <th>供货金额</th>
                <th>备注</th>
            </tr>
        </thead>
        @{;
            var resultList = viewModel.jiesuanOrderDetails;
        }
        @if (resultList != null && resultList.Count != 0)
        {
            int index = 0;
            foreach (var m in resultList)
            {
                index++;
                <tr class="@HtmlPagerHelper.TrClass(index)">
                    <td>
                        @index
                    </td>
                    <td>@m.apply_time.ToString(1)</td>
                    <td>@m.apply_username</td>
                    <td>@m.order_no</td>
                    <td>
                        货款
                    </td>
                    <td> @(MyEnumHelper.GetEnumItemDescription<SupplierPayChanner>(viewModel.aDZ_JiesuanMaster.channel))</td>
                    <td> @(MyEnumHelper.GetEnumItemDescription<include_tax>(m.include_tax))</td>
                    <td>
                        @(MyEnumHelper.GetEnumItemDescription<CurrencyType>(m.currency_type))
                    </td>
                    <td>@m.order_money.ToString("N2")</td>
                    <td>@m.supply_money.ToString("N2")</td>
                    <td>@m.remark</td>
                </tr>
            }
            <tr>
                <td colspan="20"></td>
            </tr>
        }
    </table>
    <input type="hidden" name="aDZ_JiesuanMaster.supplier_id" value="@viewModel.aDZ_JiesuanMaster.supplier_id" />
</form>
@{
    Html.RenderPartial(Url.Content("~/Views/Common/jiesuanlog.cshtml"), viewModel.aDZ_JiesuanMaster.jiesuan_id);
}
<script>
    var cancelButton =
        {
            text: '取消',
            elCls: 'button',
            handler: function () {
                this.close();
            }
        };
    reloadHandler = function () {
        $("#backid").click();
    }

    var rules = {
        'aDZ_JiesuanMaster.jiesuan_money_real': { required: true, IsBigThan0: true }
    };
    var messages = {
        //'aDZ_GoodsMaster.goods_unit': { required: '售卖单位必选' },
    };

    var validator = $('#S_Form').validate({
        errorLabelContainer: $("#errorContainer"),
        errorElement: "span",
        rules: rules,
        messages: messages,
        submitHandler: function (form) {
            $(form).ajaxSubmit(function (result) {
                ShowActionResult(result, function () {});
            });
        }
    });

    function showpayinfo() {
        var supplierdetails_id = @viewModel.aDZ_JiesuanMaster.supplierdetails_id;

        var url = "@Url.Action("GetpayInfo", "common")";
        var parameter = {
            supplierdetails_id: supplierdetails_id
        };
        $.post(url, parameter, function (result) {
            if (result) {
                var html = "";
                if (result.currency_type == @((int)CurrencyType.RMB))
                    html += "                付款货币：人民币<br />";
                if (result.currency_type == @((int)CurrencyType.Dollar))
                    html += "                付款货币：美金<br />";

                if (result.is_invoice ==  @((int)include_tax.HasTax))
                    html += "                是否开票：开票<br />";
                if (result.is_invoice ==  @((int)include_tax.NoTax))
                    html += "                是否开票：不开票<br />";

                if (result.channel ==  @((int)SupplierPayChanner.Bank)) {
                    html += "                付款渠道：银行转账<br />";
                    html += "                收款方开户行：" + result.bank_name + " " + result.branch_bank_name+"<br />";
                    html += "                收款方银行账号：" + result.bank_account_name +"<br />";
                    html += "                收款方银行开户名：" + result.bank_account +"<br />";
                }
                if (result.channel ==  @((int)SupplierPayChanner.Alipay)) {
                    html += "                付款渠道：支付宝转账<br />";
                    html += "                支付宝账号：" + result.alipay_account+"<br />";
                }
                if (result.channel ==  @((int)SupplierPayChanner.Weixin)) {
                    html += "                付款渠道：微信转账<br />";
                    html += "                微信账号：" + result.wechat_account+"<br />";
                }
                $("#tdPayInfo").html(html);
            }
        });
    }

    $(document).ready(function () {
        showpayinfo();
    });


    $("#caiwupass").click(function () {
        var jiesuan_money_real = $("#jiesuan_money_real").val();
        if (jiesuan_money_real <= 0) {
            BUI.Message.Alert("请输入正确的实际结算金额", 'warning');
            return;
        }
        BUI.Message.Show({
            title: '提示',
            msg: '确定要审核通过结算吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("caiwupassjiesuan", "jiesuan")";
                      parameter = {
                          jiesuan_id: @viewModel.aDZ_JiesuanMaster.jiesuan_id,
                          jiesuan_money_real: jiesuan_money_real,
                          remark: $("#remark").val()
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    });

    $("#caiwurefuse").click(function () {
        var reject_reson = $("#reject_reson").val();
        if (reject_reson == "") {
            BUI.Message.Alert("请输入驳回原因", 'warning');
            return;
        }
        BUI.Message.Show({
            title: '提示',
            msg: '确定要驳回结算吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("caiwurefusejiesuan", "jiesuan")";
                      parameter = {
                          jiesuan_id: @viewModel.aDZ_JiesuanMaster.jiesuan_id,
                          reject_reson: reject_reson
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    });

</script>
